<template>
	<view class="xc-wrap">
		<uv-alert title="当前为预览模式,无法提交" type="error"></uv-alert>
		<xa-paper-displayPaper :preview="true" :data="sr" @reset_parent="public_reset"></xa-paper-displayPaper>
	</view>
</template>

<script>
	import config from "@/config/config.js";
	import xcUniappUtils from '@/library/xcore/js/XcUniappUtils.js';
	import xcHttpUtils from '@/library/xcore/js/XcHttpUtils.js';
	import xcViewUtils from '@/library/xcore/js/XcViewUtils.js';
	import xcLangUtils from '@/library/xcore/js/XcLangUtils.js';
	import {
		xsStringUtils,
		xsDateUtils,
		xsArrayUtils
	} from 'xstack-for-javascript';

	export default {
		data() {
			return {
				config: config,
				xsStringUtils: xsStringUtils,
				xsDateUtils: xsDateUtils,
				sp: {
					id: null
				},
				sr: {
					paper: [],
					questionjson: [],
				},
				control: {}
			}
		},
		onLoad(options) {
			let that = this;
			let sp_id = options.id ? options.id : xcHttpUtils.getUrlParam(options, "id");
			that.sp.id = parseInt(sp_id);
			that.xinit();
		},
		onShow() {
			let that = this;
			xcUniappUtils.onShow(function() {
				that.public_show();
			});
		},
		onPullDownRefresh() {
			let that = this;
			setTimeout(function() {
				that.public_show();
				uni.stopPullDownRefresh();
			}, 1000);
		},
		methods: {
			xinit() {
				let that = this;
				if (window) {
					window.themepreview = that.themepreview;
					// setTimeout(function(){
					// 	that._test_themepreview();
					// },1000);
				}
			},
			public_reset() {
				let that = this;
				that.public_show();
			},
			public_show() {
				let that = this;
				xcHttpUtils.get('csmwj/xpmy_api/paper', {
					'id': that.sp.id,
					'preview': 'Y'
				}, function(res) {
					that.sr.paper = res.paper;
					that.sr.questionjson = res.questionjson;
					xcLangUtils.switchLocale((that.sr.paper.locales == 'en') ? 'en' : 'zh');

					uni.setNavigationBarTitle({
						title: that.sr.paper.themetopnavigationtitle
					});
				}, function(msg) {
					that.control.currentpage = 'none';
				});
			},
			_test_themepreview(){
				let that = this;
				
				window.themepreview({
					"themebannertype": "STRING",
					"themebannerstring": "xx33333333333",
					"themebannerstringstyle": "font-size:38px;color:yellow;font-weight:bold;",
					"themebannerstringdivstyle": "background-color:blue;text-align:center",
					"themebannerimage": "http://133.fa.net/uploads/20220410/d3f610bb684cb727a2e7b06f8164bec2.jpg",
					"themebannerimages": "http://133.fa.net/uploads/20220410/d3f610bb684cb727a2e7b06f8164bec2.jpg,http://133.fa.net/uploads/20220410/d3f610bb684cb727a2e7b06f8164bec2.jpg",
					"themelogoimage": "http://133.fa.net/assets/img/qrcode.png",
					"themelogodivstyle": "background-color:red;text-align:right;padding:10px 10px 10px 10px;",
					"themetitlefont": "color:green;font-size:55px;font-weight:bold;",
					"themetitledivstyle": "background-color:yellow",
					"themequestionfont": "font-size:18px;color:yellow;font-weight:bold;",
					"themequestiondivstyle": "background-color:blue;",
					"themeoptionsfont": "font-size:12px;color:#00f000;font-weight:bold;",
					"themeoptionsdivstyle": "background-color:yellow;",
					"themesubmitstring": "SSubmit",
					"themesubmitdivstyle": "background-color:yellow;",
					"themetitleshow": "Y",
					"themequestionnoshow": "N",
					"themewelcomefont": "font-size:24px;color:#333333;background-color:red;",
					"themewelcomedivstyle": "border:1px solid red;",
					"themeendfont": "font-size:24px;color:#111111;background-color:red;",
					"themeendedivstyle": "border:1px solid red;"
				});
			},
			themepreview(themes) {
				console.log("themepreview", themes);
				let that = this;
				for (let index in themes) {
					console.log(index,themes[index]);
					this.sr.paper[index] = themes[index];
				}
				uni.setNavigationBarTitle({
					title: that.sr.paper['themetopnavigationtitle']
				})
				console.log("themepreview=", this.sr.paper);
			},
		}
	}
</script>

<style lang="scss">

</style>